package leetcode.秋招.广;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author ：zsy
 * @date ：Created 2021/9/17 21:42
 * @description：
 */
public class Main5 {
    static List<String> list = new ArrayList<>();
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        recursionArrange(s.toCharArray(), 0, s.length() - 1);
        list.sort(String::compareTo);
        for (String s1 : list) {
            System.out.println(s1);
        }
    }

    private static void recursionArrange(char[] arrayA, int start, int end) {
        if (end <= 1) return;
        if (start == end) {
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < arrayA.length; i++) {
                builder.append(arrayA[i]);
            }
            list.add(builder.toString());
        } else {
            for (int i = start; i <= end; i++) {
                swap(arrayA, i, start);
                recursionArrange(arrayA, start + 1, end);
                swap(arrayA, i, start);
            }
        }
    }

    private static void swap(char[] arrayA, int m, int n) {
        char temp = arrayA[m];
        arrayA[m] = arrayA[n];
        arrayA[n] = temp;
    }
}
